from django.shortcuts import render
from django.http import JsonResponse,HttpResponse
from rest_framework.decorators import action
from rest_framework.viewsets import ModelViewSet
from .serializers import *
from .models import Interview
from django_filters import rest_framework as filters
from tool.GlobaPagination import MyPageNumberPagination
# from rest_framework
# Create your views here.


# 面试过滤器
class InterviewFilter(filters.FilterSet):
    name = filters.CharFilter(lookup_expr='contains')
    # fields = {
    #     'name':['icontains']
    # }
    class Meta:
        model = Interview
        fields = '__all__'
        exclude = ['record_src']


# 面试
class InterviewModelViewSet(ModelViewSet):
    # 查询集
    queryset = Interview.objects.all()
    # 序列化器
    serializer_class = InterviewSerializer
    # 过滤器
    filter_backends = (filters.DjangoFilterBackend,)
    # filterset_fields = ('name',)
    filterset_class = InterviewFilter
    pagination_class = MyPageNumberPagination
    # @action(methods=['post'],detail=False,url_path='upload')
    # def upload(self,request):
    #     file = request.data
    #     f = open(file['aa'],'rb')
    #     print(f)
    #
    #     return JsonResponse({'code':200})


# vueelement-admin登录接口
def Login(request):
    if request.method == 'POST':
        return JsonResponse({ "code": 20000, "data": { "token": "admin" } })
    return HttpResponse(1)

def Login1(request):
    if request.method == 'GET':
        if request.GET.get("token") == 'admin':
            return JsonResponse({
            "code": 20000,
            "data": {
                "roles": ['admin'],
                "introduction": 'I am a super administrator',
                "avatar": 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
                "name": 'Super Admin'
            }
        })
    return HttpResponse(1)


